﻿@{
    ViewBag.Title = "ReportPublish";
    Layout = "~/Views/Shared/_LayoutChild.cshtml";
}
@using Agro.Web;
@section head {
    @if (false)
    {<script src="~/Scripts/jquery-1.6.4-vsdoc.js" type="text/javascript"></script>}
    <link href="@Url.Content("~/Content/zTreeStyle/zTreeStyle.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery.ztree.all-3.0.min.js")" type="text/javascript"></script>
    @Html.Partial("_JqGrid")
    <script language="javascript" type="text/javascript">
        var selectId = "";
        var gridId = "#tableId";
        var treeObj;
        var messagetype = "receive";
        var Orgid=@ViewBag.Organization_Id;
        $(document).ready(function () {
            //loadOrganization(false); //checkenable 
            funGridInit();
            $("#MessageMenu div").hover(
                      function () {

                          $(this).addClass("navHover");

                      },
                      function () {
                          if ($(this).attr("isselect") == "true") {

                          }
                          else {
                              $(this).removeClass("navHover");

                          }
                      }
                    );
            $("#MessageMenu div").click(function () {
                NodeName = $(this).text();
                $("#MessageMenu div").attr("isselect", false);
                $("#MessageMenu div").removeClass("navHover");
                $(this).attr("isselect", true);
                $(this).addClass("navHover");
                messagetype = $(this).attr("type");
                Search();
            });
            $("#MessageMenu div:eq(0)").trigger("click");

        });
        function zTreeOnClick(event, treeId, treeNode, clickFlag) {
            curSelectNode = treeNode;
            selectId = treeNode.organization_id;
            $(gridId).trigger("reloadGrid");
        }
        function zTreeMenuCheck(event, treeId, treeNode) {
            return;
        }
        function zTreeOnAsyncSuccess(event, treeId, treeNode) {
            treeObj = $.fn.zTree.getZTreeObj(treeId);
        }
        function Search() {
            //查询
            $(gridId).setGridParam({ page: 1 });
            $(gridId).trigger("reloadGrid");
        }

        function Delete() {
            //删除
            $.funListDelete(gridId, "Message_ID", '@Url.Content("~/SystemManage/Message/MessageDelete")');
        }

        function SendMessage(type) {
            //发送消息
            var u = "/SystemManage/Message/SendMessage";
            if(type=="add") selectId="";//如果type是add即发送新消息
            parent.asyncbox.open({
                url: u,
                data: "id="+selectId,
                title: "发送消息",
                width: 600,
                height: 400,
                scroll: 'no',
                modal: true,
                btnsbar: type=="add"?parent.$.btn.OKCANCEL:parent.$.btn.CANCEL, //按钮栏配置请参考 “辅助函数” 中的 $.btn。
                callback: function (action, opener) {
                 var t = this;
                    if (action == 'ok') {
                        DialogFrame($(this).attr("id")).Save(t);
                        return false;
                    }
                    if (action == 'cancel') {
                    $(gridId).trigger("reloadGrid");//些处刷新，用以更新阅读状态
                        return;
                    }
                }
            });
        }
        function funGridInit() {
            //初始化表格
            var option = {
                height: $("#divGridContainer").height() - 51,
                width: $("#divGridContainer").width() - 2,
                url: '@Url.Content("~/SystemManage/Message/GetMessageList")',
                autowidth: false,
                datatype: "json",
                multiselect: true,
                sortname: 'Message_CreateTime',
                sortorder: 'desc',
                colModel: [
                { label: '接收单位', name: 'ReceiveOrgname', width: 150 },
                { label: '发送单位', sortable: false, hidden: true, name: 'Message_SendOrgid', width: 100 },
                { label: '阅读状态', name: 'Message_Status', width: 60, align: "center", formatter: 'select', editoptions: { value: "0:未读;1:已阅"} },
                { label: '消息标题', name: 'Message_Title', width: 150,formatter: 'StringFmatter' },
                { label: '消息内容', name: 'Message_Content', width: 250,formatter: 'StringFmatter' },
                { label: '附件名', name: 'Message_AttachmentName', width: 200 },
                { label: '发送时间', name: 'Message_CreateTime', width: 110 },
                { label: '发送单位', name: 'SendOrgname', width: 150 },
                { label: '发送人', align: "center", sortable: false, name: 'User_Name', width: 80 },
                { label: 'ID', hidden: true, name: 'Message_ID', width: 80 }
   	            ],
                onSelectRow: function (rowid, cellname, value, iRow, iCol) {
                    selectId = $(gridId).getCell(rowid, "Message_ID");
                },
                ondblClickRow: function (rowid) {
                 if (rowid > 0) {
                        selectId = $(gridId).getCell(rowid, "Message_ID");
                        SendMessage('read');   
                    }
                },
                beforeRequest: function (d) {
                    var data = { messagetype: messagetype,id:Orgid };
                     $(gridId).jqGrid('setGridParam', { postData: data });
                }
            };
            var o = jqGridHelper.getConfig("#pageId", option);
            $(gridId).jqGrid(o);
        }
    </script>
}
<!--头部导航,不用时可以去掉-->
<div class="ui-layout-north">
    <div id="headertitle">
    </div>
    <div class="buttonlist" style="float: right; height: 34px; line-height: 36px; margin-right: 20px;">
            @Html.ButtonExt("发送消息", "email.png", "XXGL_ADD", "SendMessage('add');")
        @Html.ButtonExt("删除", "delete.png", "WJGL_DEL", "Delete();")
        
@*        <a onclick="SendMessage('add')" class="button green"><span class="icon-botton" style="background: url('/Content/16/email.png') no-repeat scroll 0px 4px;">
        </span>发送消息</a> <a onclick="Delete()" class="button green"><span class="icon-botton"
            style="background: url('/Content/16/delete.png') no-repeat scroll 0px 4px;"></span>
            删除</a> *@
            
            <a onclick="Search()" class="button green"><span class="icon-botton" style="background: url('/Content/16/search.png') no-repeat scroll 0px 4px;">
            </span>查询</a>
    </div>
</div>
<!--左侧导航，不用时直接去掉-->
<div class="ui-layout-west  navPanelMini ui-layout-pane ui-layout-pane-west ui-layout-pane-hover ui-layout-pane-west-hover ui-layout-pane-open-hover ui-layout-pane-west-open-hover"
    id="MessageMenu">
    <div type="receive">
        <img src="/Content/32/171.png"  style="width:32px; height:32px;"/>已接收</div>
    <div type="send">
        <img src="/Content/32/172.png" style="width:32px; height:32px;" />已发送</div>
</div>
<!--主窗体，页面都需要的div-->
<div id="divGridContainer" class="ui-layout-center" style="overflow: auto;">
    <table id="tableId">
    </table>
    <div id="pageId">
    </div>
</div>
